<?php 
require_once('../Connections/mysql.php'); 
mysql_select_db($database_mysql, $mysql);
?>
<?php
//导入map文件
include("../conf/map.php");
mysql_query("DROP TABLE map_backup",$mysql);
mysql_query("RENAME TABLE map TO map_backup",$mysql);
mysql_query("CREATE TABLE `map` (
  `id` int(11) NOT NULL auto_increment,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `items` longtext character set latin1 NOT NULL,
  `monster_group` longtext character set latin1 NOT NULL,
  `monsters` text character set latin1 NOT NULL,
  `pc` text character set latin1 NOT NULL,
  `npc` longtext character set latin1 NOT NULL,
  `event` text character set latin1 NOT NULL,
  `type` text character set latin1 NOT NULL,
  `description` longtext character set latin1 NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8",$mysql);
echo mysql_error();
for ($x=0;$x<$map_max_x;$x++)
{
	for ($y=0;$y<$map_max_y;$y++)
	{
		mysql_query("INSERT INTO MAP (x,y) values ($x,$y)",$mysql);
		echo mysql_error();
	}
}

//将map文件细节提交到服务器的函数。由于使用array_walk()，$mysql需要被传递。
function update_map($map_array, $map_array_key, $mysql)
{
	$monster_group=mysql_real_escape_string(json_encode($map_array['monster_group']));
	$npc=mysql_real_escape_string(json_encode($map_array['npc']));
	$items=mysql_real_escape_string(json_encode($map_array['items']));
	$description=mysql_real_escape_string(json_encode($map_array['description']));
	$type=mysql_real_escape_string(json_encode($map_array['type']));
	$map_querry="UPDATE map 
	SET 
	monster_group='$monster_group',
	npc='$npc',
	items='$items',
	description='$description'
	WHERE
	x=$map_array[0] and y=$map_array[1]";
	mysql_query($map_querry,$mysql);
	echo mysql_error();
	echo $map_array[0]." ".$map_array[1]." ".$monster_group."  ".$npc."  ".$items."<br/>";
}
//循环查询$map表格
array_walk($map1,'update_map',$mysql);
?>